<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$nickname=pdo_getcolumn('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_SESSION['uid']),'nickname');
$return['nickname']=$nickname;
if($_RQ['op']=='main'){
	$setting=$this->plugin_setting('setting');
	$auctionset=$this->plugin_setting('auction');
	$setting['hdps']=json_decode($setting['hdps'],true);
	$setting['footernav']=json_decode($setting['footernav'],true);
	$orderset=$this->plugin_setting('order');
	$pid = intval($_RQ['pid']);
	$cid = intval($_RQ['cid']);
	if($cid){
		$_SESSION['cid'] = $cid;
		$return['params']['cid']=$cid;
	}
	if($pid){
		$_SESSION['pid'] = $pid;
		$_SESSION['cid'] = 0;
		$_SESSION['status'] = 0;
		$return['params']['pid']=$pid;
	}
	if($_RQ['page'] && $_RQ['datanew'] !=1 && !$cid){
		$cid = $_SESSION['cid'];
		$pid = $_SESSION['pid'];
	}
	$return['cid']=$cid;
	if($cid){
		$PClass = pdo_get('jy_jdpm_goods_group',array('uniacid'=>$_SESSION['uniacid'],'id' => $cid));
		$pid = $PClass['pid'];
		$return['PClass'] = pdo_getcolumn('jy_jdpm_goods_group',array('uniacid'=>$_SESSION['uniacid'],'id' => $pid),'title');
		$return['channelName']=$PClass['title'];
	}elseif($pid){
		$PClass = pdo_get('jy_jdpm_goods_group',array('uniacid'=>$_SESSION['uniacid'],'id' => $pid));
		//$cid = $pid;
		$return['PClass']=$PClass['title'];
		$cid = pdo_getall('jy_jdpm_goods_group',array('uniacid'=>$_SESSION['uniacid'],'pid'=>$pid),array('id'),'id');
		$cid=array_keys($cid);
		$cid[]=$pid;
	}
	$return['pid']=$pid;
	$return['channel'] = pdo_getall('jy_jdpm_goods_group',array('uniacid'=>$_SESSION['uniacid'],'pid' => 0),'','','paixu asc');
        /*** 分类数据 START ***/
        $Classify = pdo_getall('jy_jdpm_goods_group',array('uniacid'=>$_SESSION['uniacid'],'pid' => $pid),'','','paixu desc');
		$return['Classify']=$Classify;
		
        /*** 分类数据 END ***/
        /*** 列表数据 START ***/
        /** 状态 **/
        $status = intval($_RQ['status']);
		if($status){
			$_SESSION['status']=$status;
		}else{
			$status = $_SESSION['status'];
		}
		$return['status']=$status;
		$order = ' g.id desc';
		//exi('!!!!'.$status,'error');
        if ($status == 1) {
            $where +=' AND a.starttime < '.time();
            $where +=' AND a.endtime > '.time();
        } elseif ($status == 3) {
            $where +=' AND a.starttime >'.time();
        } elseif ($status == 2){
            $where +=' AND a.endtime < '.time();
            $order     = ' a.endtime DESC';
        }
        /** 筛选条件 **/
		$pindex = max(1, intval($_RQ['page']));
		$psize = 20;
		$total='';
		if($cid){
			$goodswhere = array('uniacid'=>$_SESSION['uniacid'],'cid'=>$cid);
		}else{
			$goodswhere = array('uniacid'=>$_SESSION['uniacid'],);
		}
		$goodids=pdo_getall('jy_jdpm_goods',$goodswhere,array('id'),'id');
		if(!empty($goodids)){
			$goodids=array_keys($goodids);
		}else{
			$goodids = '-1';
		}
		$params=array(
			'goodsid'=>$goodids,
			'uniacid'=>$_SESSION['uniacid'],
			'hide'=>0,
			'endstatus <'=>3,
		);
		$return['params']=array();
		$ishot=intval($_RQ['ishot']);
		if($ishot){
			$params['ishot']=1;
			$return['params']['ishot']=1;
		}
		$keyword = trim($_RQ['keyword']);	
		if(!empty($keyword)){
			$params['pname like']='%'.$keyword.'%';
			$return['params']['keyword']=$keyword;
			$logsearch = pdo_get('jy_jdpm_search', array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'key'=>$keyword),'mid');
			if($logsearch){
				pdo_update('jy_jdpm_search', array('num +='=>1), array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'key'=>$keyword));
			}else{
				pdo_insert('jy_jdpm_search', array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'key'=>$keyword,'createtime'=>TIMESTAMP,'num'=>1));
			}
		}
		if ($status == 1) {
            $params['starttime <']=TIMESTAMP;
			$params['endtime >']=TIMESTAMP;
        } elseif ($status == 3) {
            $params['starttime >']=TIMESTAMP;
        } elseif ($status == 2){
            $params['endtime <']=TIMESTAMP;
        }
		$goods=pdo_getslice('jy_jdpm_auction',$params,array($pindex,$psize),$total,array(),'','endtime desc');
		if($goods){
			foreach ($goods as $key => &$value) {
				$goodinfo = get_goodsinfo($value['goodsid']);
				$goodinfo['images'] = json_decode($goodinfo['images'],true);
				$value['status'] = $value['starttime'] > time() ? 0 : ($value['endtime'] > time() ? 1 : 2);
				$value['image'] = $goodinfo['image'];
				$value['bidding']=$value['mid']>0 ?($value['nowprice']+($value['onset']/10)):$value['onset'];
				$value['clinch']=$value['mid']>0?$value['nowprice']:$value['onset'];
				$value['bzprice']=$value['mid']>0?(($value['nowprice'] +($value['onset']/10))>=($value['onset']*$orderset['onsetbi'])?($value['nowprice']+($value['onset']/10)):($value['nowprice']+($value['onset']/10))/2):$value['onset']/2;
				$value['ingname']=substr($value['mid'] ,0, 1) . '******' . substr($value['mid'] , -1);
				$value['endtime2'] = date('Y/m/d H:i:s',$value['endtime']);
				$value['starttime2'] = date('Y/m/d H:i:s',$value['starttime']);
				$value['count'] = pdo_count('jy_jdpm_money_log',array('pid'=>$value['pid'],'channel'=>2,'type'=>1));
	
			}
		}
        $return['goods']=$goods?$goods:array();
		$totalpage=ceil($total/$psize);
		$totalpage=intval($totalpage);
		$return['totalpage'] =$totalpage;
		$return['params']['page'] =$pindex;
	$return['list']=array();
	$return['searchstart']=intval($_RQ['searchstart']);
	$return['hotlist'] = pdo_getslice('jy_jdpm_search',array('uniacid'=>$_SESSION['uniacid'],),array($pindex,10),$total,'','','createtime Desc');
	$return['historylist'] = pdo_getslice('jy_jdpm_search',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),array($pindex,10),$total,'','','num DESC,createtime Desc');
	$return['sharedata'] =array(
			'title'=>$PClass['title'].'-'.$this->plugin_setting('basic')['title'],
			'desc'=>$PClass['title'].'-'.$this->plugin_setting('basic')['title'],
			'link'=>custom_url('jy_jdpm/goodslist//pid='.$pid.'&cid='.$cid),
			'imgUrl'=>$_SESSION['account']['logo'] ? $_AR['siteroot'].'resource/'.$_SESSION['account']['logo'] : $_AR['siteroot'].'core/resource/images/nopic.jpg',
	);
	$title = $PClass['title']?$PClass['title']:($keyword?$keyword:'拍品列表');
	set_html('title',$title.'-'.$this->plugin_setting('basic')['title']);
	$return['extradata']=array();
	$return['ntime']=TIMESTAMP;
	exi($return);
}
?>